import 'package:flutter/cupertino.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';

class TextUtils {
  static String getStr(String text,
      {Key key, String befor = "", String after = "", String defaultStr = ""}) {
    return befor + (text == null ? defaultStr : text) + after;
  }

  static String getTimeStr(String startTime, String endTime,
      {Key key, String befor = "", String after = "", String defaultStr = ""}) {
    return befor +
        (startTime == null ? defaultStr : startTime) +
        "--" +
        (endTime == null ? defaultStr : endTime) +
        after;
  }

  static content(String befor, String text, var beforSize, var textSize) {
    return Container(
      color: SQColor.white,
      child: Row(
        children: <Widget>[
          Text(befor,
              style: TextStyle(color: SQColor.per38Black, fontSize: beforSize)),
          Expanded(
              flex: 1,
              child: Text(text,
                  softWrap: true,
                  style:
                      TextStyle(color: SQColor.per60Black, fontSize: textSize)))
        ],
      ),
    );
  }

  static richText(String befor, var beforSize, var beforColor, String text,
      var textSize, var textColor,
      {Key key, int maxLines, OnClick click}) {
    if (click == null) {
      return maxLines != null
          ? RichText(
              softWrap: true,
              maxLines: maxLines,
              overflow: TextOverflow.ellipsis,
              text: TextSpan(children: <TextSpan>[
                TextSpan(
                    text: befor,
                    style: TextStyle(color: beforColor, fontSize: beforSize)),
                TextSpan(
                    text: text,
                    style: TextStyle(color: textColor, fontSize: textSize)),
              ]),
            )
          : RichText(
              softWrap: true,
//        maxLines: 2,
//            overflow: TextOverflow.ellipsis,
              text: TextSpan(children: <TextSpan>[
                TextSpan(
                    text: befor,
                    style: TextStyle(color: beforColor, fontSize: beforSize)),
                TextSpan(
                    text: text,
                    style: TextStyle(color: textColor, fontSize: textSize)),
              ]),
            );
    } else {
      return GestureDetector(
        child: maxLines != null
            ? RichText(
                softWrap: true,
                maxLines: maxLines,
                overflow: TextOverflow.ellipsis,
                text: TextSpan(children: <TextSpan>[
                  TextSpan(
                      text: befor,
                      style: TextStyle(color: beforColor, fontSize: beforSize)),
                  TextSpan(
                      text: text,
                      style: TextStyle(color: textColor, fontSize: textSize)),
                ]),
              )
            : RichText(
                softWrap: true,
//        maxLines: 2,
//            overflow: TextOverflow.ellipsis,
                text: TextSpan(children: <TextSpan>[
                  TextSpan(
                      text: befor,
                      style: TextStyle(color: beforColor, fontSize: beforSize)),
                  TextSpan(
                      text: text,
                      style: TextStyle(color: textColor, fontSize: textSize)),
                ]),
              ),
        onTap: () {
          click();
        },
      );
    }
  }
  static cRichText(String befor,
      {Key key,
        var beforSize,
        var beforColor,
        String text,
        var textSize,
        var textColor,
        int maxLines,
        OnClick click}) {
    if (beforSize == null) beforSize = Dimens.textSize28;
    if (beforColor == null) beforColor = SQColor.per38Black;
    if (text == null) text = "";
    if (textSize == null) textSize = Dimens.textSize28;
    if (textColor == null) textColor = SQColor.per60Black;

    if (click == null) {
      return maxLines != null
          ? RichText(
        softWrap: true,
        maxLines: maxLines,
        overflow: TextOverflow.ellipsis,
        text: TextSpan(children: <TextSpan>[
          TextSpan(
              text: befor,
              style: TextStyle(color: beforColor, fontSize: beforSize)),
          TextSpan(
              text: text,
              style: TextStyle(color: textColor, fontSize: textSize)),
        ]),
      )
          : RichText(
        softWrap: true,
//        maxLines: 2,
//            overflow: TextOverflow.ellipsis,
        text: TextSpan(children: <TextSpan>[
          TextSpan(
              text: befor,
              style: TextStyle(color: beforColor, fontSize: beforSize)),
          TextSpan(
              text: text,
              style: TextStyle(color: textColor, fontSize: textSize)),
        ]),
      );
    } else {
      return GestureDetector(
        child: maxLines != null
            ? RichText(
          softWrap: true,
          maxLines: maxLines,
          overflow: TextOverflow.ellipsis,
          text: TextSpan(children: <TextSpan>[
            TextSpan(
                text: befor,
                style: TextStyle(color: beforColor, fontSize: beforSize)),
            TextSpan(
                text: text,
                style: TextStyle(color: textColor, fontSize: textSize)),
          ]),
        )
            : RichText(
          softWrap: true,
//        maxLines: 2,
//            overflow: TextOverflow.ellipsis,
          text: TextSpan(children: <TextSpan>[
            TextSpan(
                text: befor,
                style: TextStyle(color: beforColor, fontSize: beforSize)),
            TextSpan(
                text: text,
                style: TextStyle(color: textColor, fontSize: textSize)),
          ]),
        ),
        onTap: () {
          click();
        },
      );
    }
  }
  static sgRichText(String befor, String text) {
    return RichText(
      softWrap: true,
//            maxLines: 2,
//            overflow: TextOverflow.ellipsis,
      text: TextSpan(children: <TextSpan>[
        TextSpan(
            text: befor,
            style: TextStyle(
                color: SQColor.per38Black, fontSize: Dimens.textSize28)),
        TextSpan(
            text: text,
            style: TextStyle(
                color: SQColor.per60Black, fontSize: Dimens.textSize28)),
      ]),
    );
  }
}

typedef void OnClick();
